package com.dream.fly.juststartpractice.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: 熊海梦
 * @date: 2018/11/8 15:12
 **/
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = BizException.class)
    @ResponseBody
    public WebApiResponse<String> jsonErrorHandler(HttpServletRequest req, BizException e){
        WebApiResponse<String> r = new WebApiResponse<>();
        r.setMessage(e.getMessage());
        r.setCode(e.getCode());
        r.setData("Some Data");
        r.setUrl(req.getRequestURL().toString());
        return r;
    }
}
